
package com.jf.cloud.order.controller.supplier;

import cn.hutool.core.date.DateUtil;
import com.jf.cloud.common.order.vo.OrderCountVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.common.security.AuthUserContext;
import com.jf.cloud.order.service.SupplierOrderStatisticsService;
import com.jf.cloud.order.vo.HotProductVO;
import com.jf.cloud.order.vo.OrderOverviewVO;
import com.jf.cloud.order.vo.SupplierOrderOverviewVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.Operation;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zz
 */
@RestController("supplierOrderStatisticsController")
@RequestMapping("/s/order_statistics")
@Tag(name = "supplier-供应商订单数据统计接口")
public class OrderStatisticsController {

    @Autowired
    private SupplierOrderStatisticsService supplierOrderStatisticsService;

    @GetMapping("/order_count")
    @Operation(summary = "查询店铺各种状态下的订单数量" , description = "根据订单状态统计订单数量")
    public ServerResponseEntity<OrderCountVO> getOrderCount() {
        OrderCountVO orderCountVO = supplierOrderStatisticsService.getOrderCountOfStatusBySupplierId(AuthUserContext.get().getTenantId());
        return ServerResponseEntity.success(orderCountVO);
    }

    @GetMapping("/get_today_info_by_hour")
    @Operation(summary = "获取当天订单实时统计数据" , description = "获取当天订单实时统计数据")
    public ServerResponseEntity<SupplierOrderOverviewVO> getTodayInfoByHour() {
        SupplierOrderOverviewVO supplierOrderOverviewVO = supplierOrderStatisticsService.getTodayInfoByHour(AuthUserContext.get().getTenantId(),
                DateUtil.beginOfDay(DateUtil.date()), DateUtil.endOfDay(DateUtil.date()));
        return ServerResponseEntity.success(supplierOrderOverviewVO);
    }

    @GetMapping("/list_prod_ranking_by_payActual")
    @Operation(summary = "根据支付金额获取近30天的商品销售数据排行榜" , description = "获取近30天的商品销售数据排行榜")
    @Parameters({
            @Parameter(name = "dayCount", description = "天数（几天内的排行榜）", required = false),
            @Parameter(name = "limit", description = "排行榜条数", required = false)
    })
    public ServerResponseEntity<List<HotProductVO>> listProdRankingByPayActual(@ParameterObject @RequestParam(value = "dayCount", defaultValue = "30") Integer dayCount,
                                                                               @ParameterObject @RequestParam(value = "limit", defaultValue = "5") Integer limit) {
        List<HotProductVO> orderOverviewVOList = supplierOrderStatisticsService.listProdRankingByPayActual(AuthUserContext.get().getTenantId(), dayCount, limit);
        return ServerResponseEntity.success(orderOverviewVOList);
    }

//    @GetMapping("/get_current_month_by_day")
//    @Operation(summary = "获取当月订单的统计数据" , description = "获取当月订单的统计数据")
//    public ServerResponseEntity<OrderOverviewVO> getCurrentMonthInfoByDay() {
//        OrderOverviewVO orderOverviewVO = supplierOrderStatisticsService.getCurrentMonthByDay(AuthUserContext.get().getTenantId(),
//                DateUtil.beginOfMonth(DateUtil.date()), DateUtil.endOfDay(DateUtil.date()));
//        return ServerResponseEntity.success(orderOverviewVO);
//    }

}
